local skel = fk.CreateSkill{
    name = "ling__xiasanlan",
}

Fk:loadTranslationTable{
    ["ling__xiasanlan"] = "下三滥",
    [":ling__xiasanlan"] = [[出牌阶段限一次，你可以指定一名其他角色，然后选择以下一项：
    合欢散：将一张【动摇军心】置入其判定区，若判定为红桃则其失去1点体力。
    石灰粉：其随机弃置两张牌，优先弃置【闪】。
    龙爪手：对其随机造成0~2 点伤害，其随机摸0~2 张牌。
    其猜测你会选择哪项，猜对则不执行。]],
    ["#ling__xiasanlan-invoke"] = "下三滥：你可以选择一项：",
    ["#ling__xiasanlan-guess"] = "下三滥：你可以猜测韦小宝选择的诡计，猜测成功则不执行：",
    ["ling__xiasanlan_1"] = "合欢散",
    [":ling__xiasanlan_1"] = "合欢散：将一张【动摇军心】置入其判定区，若判定为红桃则其失去1点体力。",
    ["ling__xiasanlan_2"] = "石灰粉",
    [":ling__xiasanlan_2"] = "石灰粉：其随机弃置两张牌，优先弃置【闪】。",
    ["ling__xiasanlan_3"] = "龙爪手",
    [":ling__xiasanlan_3"] = "龙爪手：对其随机造成0~2 点伤害，其随机摸0~2 张牌。",
}

skel:addEffect("active", {
    anim_type = "switch",
    card_num = 0,
    target_num = 1,
    prompt = "#ling__xiasanlan-invoke",
    can_use = function(self, player)
      return player:usedEffectTimes(self.name, Player.HistoryPhase) == 0
    end,
    card_filter = function(self, player, to_select, selected)
      return false
    end,
    target_filter = function (self, player, to_select, selected)
      if #selected == 0 and to_select ~= player then
        return true
      end
    end,
    on_use = function(self, room, effect)
      local player = effect.from
      local target = effect.tos[1]
      local choices = {"ling__xiasanlan_1", "ling__xiasanlan_2", "ling__xiasanlan_3"}
      local choice = room:askToChoice(player, {
        choices = choices,
        skill_name = skel.name,
        prompt = "#ling__xiasanlan-invoke",
        detailed = true,
      })
      local guess = room:askToChoice(target, {
        choices = {"ling__xiasanlan_1", "ling__xiasanlan_2", "ling__xiasanlan_3"},
        skill_name = skel.name,
        prompt = "#ling__xiasanlan-guess",
        detailed = true,
      })
      --猜测成功则不执行
      if guess == choice then
        return 
      end
      if choice == "ling__xiasanlan_1" then
        local card = Fk:cloneCard("ling__waver_morale")
        local sub=room:getNCards(1)
        card:addSubcards(sub)
        room:useCard{
          from = player,
          tos = {target},
          card = card,
        }
      elseif  choice == "ling__xiasanlan_2" then
        local count = 2
        local cards = table.filter(target:getCardIds("he"), function (id)
          return not target:prohibitDiscard(id)
        end)
        local jink_cards=table.filter(cards, function (id)
          return Fk:getCardById(id).name == "jink"
        end)
        if #jink_cards > 0 then
          if #jink_cards > 1 then
            room:throwCard(table.random(jink_cards, count), skel.name, target, target)
          else
            room:throwCard(table.random(jink_cards, 1), skel.name, target, target)
            count = count - 1
            if count>0 and #cards > 0 then
              room:throwCard(table.random(cards, count), skel.name, target, target)
            end
          end
        elseif #cards > 0 then
          if #cards >= count then
            room:throwCard(table.random(cards, count), skel.name, target, target)
          else
            room:throwCard(table.random(cards, 1), skel.name, target, target)
          end
        end

      elseif choice == "ling__xiasanlan_3" then 
        local n = math.random(0, 2)
        room:damage{
          from = player,
          to = target,
          damage = n,
          skillName = skel.name,
        }
        local x = math.random(0, 2)
        target:drawCards(x, skel.name)
      end
    end,
  })





return skel